Skip to content

Fix warning for output_attentions=True - #40597

Merged
qubvel merged 7 commits into
huggingface:mainfrom
qubvel:add-warning-for-attn
Sep 3, 2025
Merged

qubvel merged 7 commits into
huggingface:mainfrom
qubvel:add-warning-for-attn

Conversation

@qubvel

@qubvel qubvel commented Sep 1, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

With the @check_model_inputs decorator, we no longer check and fallback to the eager attention in the Attention module's code, let's notify users to set proper attention implementation. Otherwise, we are silently getting None attentions even if we specify output_attentions=True (because the default attention is sdpa)

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qubvel
qubvel requested a review from zucchini-nlp September 1, 2025 18:15
@qubvel qubvel changed the title Fix attn_implementation for output_attentions=True Fix warning for output_attentions=True Sep 2, 2025

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks

Comment thread src/transformers/utils/generic.py Resolved
@qubvel
qubvel enabled auto-merge (squash) September 2, 2025 11:15
@qubvel

qubvel commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

cc @ydshieh to merge, CI failures are unrelated

@qubvel
qubvel merged commit 55676d7 into huggingface:main Sep 3, 2025

# Check attention implementation is properly set for capturing attention outputs
if recordable_keys.get("output_attentions", False):
supported_attn = ["eager", "eager_paged", "flex_attention"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flex attention returns the lse (like flash attention) - not really the same as what you would get with eager

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I noticed that, but that would be captured as attentions and returned in ModelOutput, if I'm no missing anything. Do you have an idea of a better warning?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have an immediate solution, but 2 suggestions:

  • Properly change what output_attentions does in the docs and enable outputting the lse (would include flash attn then for example)
  • Another separate kwarg/attr output_lse which works for flash, flex etc and not on eager for example.

Currently, we have a weird situation with flex 😅 doesnt need immediate change but maybe put it up for discussion internally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants